public LexicalUnit CreateLexicalUnit(User user) { var lexicalUnit = new LexicalUnit() { Text = Guid.NewGuid().ToString(), User = user }; _context.LexicalUnits.Add(lexicalUnit); _context.SaveChanges(); return(lexicalUnit); }
/* * (non-Javadoc) * * @see org.w3c.css.sac.DocumentHandler#property(java.lang.String, * org.w3c.css.sac.LexicalUnit, boolean) */ public virtual void property(string name, LexicalUnit value_Renamed, bool important) { // only bother validating and building if we are either inline or within // a selector tag if (!selectorOpen && !isInline) { return; } // validate the property if (validator.isValidProperty(name, value_Renamed)) { styleSheet.Append('\t'); styleSheet.Append(name); styleSheet.Append(':'); // append all values while (value_Renamed != null) { styleSheet.Append(' '); styleSheet.Append(validator.lexicalValueToString(value_Renamed)); value_Renamed = value_Renamed.getNextLexicalUnit(); } styleSheet.Append(';'); styleSheet.Append('\n'); } else { if (tagName != null) { //results.addErrorMessage("The <b>" + HTMLEntityEncoder.htmlEntityEncode(tagName) + "</b> tag had a style property that could not be accepted for security reasons. The <b>" + HTMLEntityEncoder.htmlEntityEncode(name) + "</b> property had a value of <u>" + HTMLEntityEncoder.htmlEntityEncode(validator.lexicalValueToString(value_Renamed)) + "</u>"); } else { //results.addErrorMessage("The <b>style</b> tag had a property <b>" + HTMLEntityEncoder.htmlEntityEncode(name) + "</b> that could not be accepted for security reasons. The property had a value of <u>" + HTMLEntityEncoder.htmlEntityEncode(validator.lexicalValueToString(value_Renamed)) + "</u>"); } } }
private static bool isIdentifier(LexicalUnit lu) { switch (lu) { case Identifier: case VerbatimIdentifier: case ContextualKeyword: return true; default: return false; } }
private LexicalUnit nextLexicalUnit(bool fail, LexicalUnit expected) { newLineOccured = false; while (true) { switch (lexicalUnit = scanner.nextLexicalUnit()) { case NewLine: newLineOccured = true; break; case SingleLineComment: if (docCommentEndPosition > 0 && !wasSingleLineDocComment) { docCommentStartPosition = scanner.StartPosition; docCommentEndPosition = 0; } if (this.LexicalUnitLength > 2 && scanner.Text[scanner.StartPosition + 2] == '/') { if (docCommentEndPosition == 0 || !wasSingleLineDocComment) { docCommentStartPosition = scanner.StartPosition; } wasSingleLineDocComment = true; docCommentEndPosition = scanner.EndPosition; } else { docCommentEndPosition = 0; } break; case DelimitedComment: if (this.LexicalUnitLength > 4 && scanner.Text[scanner.StartPosition + 2] == '*') { wasSingleLineDocComment = false; docCommentStartPosition = scanner.StartPosition; docCommentEndPosition = scanner.EndPosition; } else { docCommentEndPosition = 0; } break; case Whitespace: break; default: if (lexicalUnit == LexicalUnit.EndOfStream && fail) { if (expected == LexicalUnit.CloseBrace) { throw error(ParseErrorId.CloseBraceExpected); } else { throw error(ParseErrorId.UnexpectedEndOfStream); } } return lexicalUnit; } } }
private void parseFormalParameters(List<ParameterNode> parameters, LexicalUnit endLexicalUnit) { while (true) { var param = new ParameterNode(); parameters.add(param); while (lexicalUnit == LexicalUnit.OpenBracket) { param.Annotations.add(parseAnnotationSection()); } setScannerState(param); switch (lexicalUnit) { case Keyword: switch (scanner.Keyword) { case Params: param.Modifier = ParameterModifier.Params; nextLexicalUnit(true); break; case This: if (parameters.size() > 1) { throw error(ParseErrorId.UnexpectedLexicalUnit); } param.Modifier = ParameterModifier.This; nextLexicalUnit(true); break; } break; } param.Type = parseType(true); if (!isIdentifier(lexicalUnit)) { throw error(ParseErrorId.IdentifierExpected); } param.NameOffset = scanner.StartPosition; param.NameLength = getLexicalUnitLength(); param.EndPosition = scanner.EndPosition; nextLexicalUnit(true); if (param.Modifier == ParameterModifier.Params) { if (param.Type.TypeReferenceKind != TypeReferenceKind.Array) { throw error(ParseErrorId.ArrayTypeExpected); } break; } if (lexicalUnit == LexicalUnit.Comma) { nextLexicalUnit(true); } else { break; } } if (lexicalUnit != endLexicalUnit) { if (endLexicalUnit == LexicalUnit.CloseParenthesis) { throw error(ParseErrorId.CloseParenthesisExpected); } else if (endLexicalUnit == LexicalUnit.CloseBracket) { throw error(ParseErrorId.CloseBracketExpected); } else { throw error(ParseErrorId.CommaExpected); } } nextLexicalUnit(false); }
protected internal int Read(LexicalUnit unit, ref FragmentPosition position, char[] buffer, int offset, int count) { InternalDebug.Assert(count != 0); int startOffset = offset; if (unit.head != -1) { uint kind = this.runList[unit.head].MajorKind; int run = position.run; if (run == unit.head - 1) { run = position.run = unit.head; } RunEntry runEntry = this.runList[run]; if (run == unit.head || runEntry.MajorKindPlusStartFlag == kind) { int runOffset = position.runOffset; int runDeltaOffset = position.runDeltaOffset; do { InternalDebug.Assert(count != 0); if (runEntry.Type == RunType.Literal) { int literalLength = Token.LiteralLength(runEntry.Value); if (runDeltaOffset != literalLength) { if (literalLength == 1) { InternalDebug.Assert(runDeltaOffset == 0); buffer[offset++] = (char)runEntry.Value; count--; } else { InternalDebug.Assert(literalLength == 2); if (runDeltaOffset != 0) { InternalDebug.Assert(runDeltaOffset == 1); buffer[offset++] = Token.LiteralLastChar(runEntry.Value); count--; } else { buffer[offset++] = Token.LiteralFirstChar(runEntry.Value); count--; if (count == 0) { runDeltaOffset = 1; break; } buffer[offset++] = Token.LiteralLastChar(runEntry.Value); count--; } } } } else if (runEntry.Type == RunType.Normal) { InternalDebug.Assert(runDeltaOffset >= 0 && runDeltaOffset < runEntry.Length); int copyCount = Math.Min(count, runEntry.Length - runDeltaOffset); InternalDebug.Assert(copyCount != 0); { Buffer.BlockCopy(this.buffer, (runOffset + runDeltaOffset) * 2, buffer, offset * 2, copyCount * 2); offset += copyCount; count -= copyCount; if (runDeltaOffset + copyCount != runEntry.Length) { runDeltaOffset += copyCount; break; } } } runOffset += runEntry.Length; runDeltaOffset = 0; runEntry = this.runList[++run]; }while (runEntry.MajorKindPlusStartFlag == kind && count != 0); position.run = run; position.runOffset = runOffset; position.runDeltaOffset = runDeltaOffset; } } return(offset - startOffset); }